﻿using MQ.Core.Common;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace MQ.Core.Db
{
    public abstract class BaseRepository : IBaseRepository
    {
        private readonly IBaseDb db; 
        public BaseRepository(IBaseDb db)
        {
            this.db = db;
        }
        public void Add<T>(T entity) where T:class
        {
            db.Insert(entity);
        }

        public Task AddAsync<T>(T entity) where T : class
        {
            return db.InsertAsync(entity);
        }

        public void Delete<T>(T entity) where T : class
        {
            db.Delete(entity);
        }

        public Task DeleteAsync<T>(T entity) where T : class
        {
            return db.DeleteAsync(entity);
        }

        public T GetEntity<T>(long id) where T : class
        {
            throw new NotImplementedException();
        }

        public Task<T> GetEntityAsync<T>(long id) where T : class
        {
            db.Transaction(() => { });
            throw new NotImplementedException();
        }

        public void Update<T>(T entity) where T : class
        {
            db.Update(entity);
        }

        public Task UpdateAsync<T>(T entity) where T : class
        {
            return db.UpdateAsync(entity);
        }
        public abstract IEnumerable<T> GetList<T>(string query) where T : class;

        public abstract Task<IEnumerable<T>> GetListAsync<T>(string query) where T : class;

        public abstract IEnumerable<T> GetPageList<T>(Pagination pagination, string query) where T : class;

        public abstract Task<IEnumerable<T>> GetPageListAsync<T>(Pagination pagination, string query) where T : class;
        public abstract void Delete(string ids);
        public abstract Task DeleteAsync(string ids);
    }
}
